package com.tools.app.store;

import android.content.Context;
import android.content.SharedPreferences;

import com.tools.app.AppApplication;
import com.tools.app.AppConstant;
import com.tools.cleanmaster.store.CleanSharedPrefManager;

/**
 * Created by ChenLi on 2017/12/13.
 */

public class AppSharedPrefManager extends CleanSharedPrefManager {

    // 配置信息
    public static final String APP_PREF = "app_config_pref";

    // 配置
    private SharedPreferences appPref;

    public AppSharedPrefManager(AppApplication context) {
        super(context);
        appPref = context.getSharedPreferences(APP_PREF, Context.MODE_PRIVATE);
    }

    /**
     * 收到的 referrer 的time
     **/
    public void saveRTS(long time) {
        SharedPreferences.Editor editor = appPref.edit();
        editor.putLong(AppConstant.KEY_REFERRER_TIME, time);
        editor.apply();
    }

    public long getRTS() {
        return appPref.getLong(AppConstant.KEY_REFERRER_TIME, 0);
    }

    /**
     * 收到的 referrer 值
     **/
    public void saveReferrer(String referrer) {
        SharedPreferences.Editor editor = appPref.edit();
        editor.putString(AppConstant.KEY_REFERRER_VALUE, referrer);
        editor.apply();
    }

    public String getReferrer() {
        return appPref.getString(AppConstant.KEY_REFERRER_VALUE, "");
    }

    /**
     * 收到的 referrer 值
     **/
    public void saveReferrerForGA(String referrer) {
        SharedPreferences.Editor editor = appPref.edit();
        editor.putString(AppConstant.KEY_REFERRER_GA_VALUE, referrer);
        editor.apply();
    }

    public String getReferrerForGA() {
        return appPref.getString(AppConstant.KEY_REFERRER_GA_VALUE, "");
    }

    public void setAFInstallConversionData(String data) {
        appPref.edit().putString(AppConstant.KEY_AF_INSTALL_DATA, data).apply();
    }

    public String getAFInstallConversionData() {
        return appPref.getString(AppConstant.KEY_AF_INSTALL_DATA, "");
    }

    public void setAFOpenData(String data) {
        appPref.edit().putString(AppConstant.KEY_AF_OPEN_DATA, data).apply();
    }

    public String getAFOpenData() {
        return appPref.getString(AppConstant.KEY_AF_OPEN_DATA, "");
    }

}
